$(()=>{
    let $get = $("#get");
    let $inputbox = $("#inputbox");
    $inputbox.focus();
    let $main = $("#main");
    let $table = $("#table");
    let $item1 = $("#item1");
    let $item2 = $("#item2");
    let $item3 = $("#item3");
    let $item4 = $("#item4");
    let $item5 = $("#item5");
    let $item6 = $("#item6");
    let $item7 = $("#item7");
    let $item8 = $("#item8");
    let $item9 = $("#item9");
    let $reload_song = $("#reload_song");
    $inputbox.keydown(e=>{if (e.keyCode===13)$get.click();});
    $(document).keydown(e=>{if(e.keyCode===36){if (e.ctrlKey){if(confirm("是否要返回上一页？")){location.href = "./?/index";}}else{if(confirm("是否要返回首页？")){history.back();}}}else if(e.keyCode===45){$inputbox.focus();}});
    $get.click(()=>{
        $main.addClass("el-loading");
        $.post("#",{},text=>{
            $main.removeClass("el-loading");
            $table.hide();
            $table.removeClass("el-loading");
            let data = JSON.parse(text);
            if (data.success){
                $item1.text(data.data.id);
                $item2.text(data.data.content);
                $item3.html(`<img src="${data.data.avatarUrl}" width="200" alt="头像">`);
                $item4.text(data.data.songName);
                $item5.text(data.data.name);
                $item6.text(data.data.auther);
                $item7.html(`<img src="${data.data.picUrl}" width="200" alt="封面">`);
                $item8.html(`<audio src="${data.data.mp3url}" controls>`);
                $item9.html(`<a href="${data.data.mp3url}" download="${data.data.mp3url}">${data.data.mp3url}</a>`);
                $table.fadeIn();
            }else {
                /*这里貌似不会失败，应该不会执行*/
                alert(data.message);
            }
            /*console.log(text);*/
        });
    });
    $reload_song.click(()=>{
        $main.addClass("el-loading");
        let id = $item1.text();
        $.post("./?/netease_music",{
            id:id
        },text=>{
            $main.removeClass("el-loading");
            $table.hide();
            $table.removeClass("el-loading");
            let data = JSON.parse(text);
            if (data.success){
                $item8.html(`<audio src="${data.mp3url}" controls>`);
                $item9.html(`<a href="${data.mp3url}" download="${data.mp3url}">${data.mp3url}</a>`);
                $table.fadeIn();
            }else {
                $reload_song.click();
            }
        });
    });
});
